package cn.itcast.Thread;

/**
 * @Author : 叶荻风
 * @create : 2024/8/12 15:34
 */
public class DeadLockDemo {
    private static Object resource1 = new Object();
    private static Object resource2 = new Object();
    public static void main(String[] args) {
        new Thread(()->{
            synchronized (resource1){

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (resource2){
                    System.out.println("Thread-A is here");
                }
            }
        }).start();
        new Thread(()->{
            synchronized (resource2){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (resource1){
                    System.out.println("Thread-B is here");
                }
            }
        }).start();
    }
}
